package fhp.hlhj.giantfold.customView

import android.animation.ObjectAnimator
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.liaoinstan.springview.container.BaseHeader
import fhp.hlhj.giantfold.R
import kotlinx.android.synthetic.main.pull_header.view.*
/**
 * author: FHP
 * data: on 2017\11\17 0017 18:11
 * E-Mail: 103945089@qq.com
 */
class MyHeader : BaseHeader() {
    private var headView:View?=null
    private lateinit var animator :ObjectAnimator
    override fun onLimitDes(rootView: View?, upORdown: Boolean) {
        if (!upORdown) {
            headView!!.tvHint.text = "送一哈，马上刷新"
        } else {
            headView!!.tvHint.text = "拉一下，刷新一哈"
        }
    }

    override fun onFinishAnim() {
        headView!!.img.setImageResource(R.mipmap.huanqian_xialashuaxhou)
        animator.end()
        headView!!.tvHint.setText("刷新成功")
    }

    override fun onStartAnim() {
        animator = ObjectAnimator.ofFloat(headView!!.img, "rotation", 0f, 360f) as ObjectAnimator
        animator.repeatCount=-1
        animator.start()
        headView!!.tvHint.setText("刷新中")
    }

    override fun onDropAnim(rootView: View?, dy: Int) {
    }

    override fun getView(inflater: LayoutInflater?, viewGroup: ViewGroup?): View? {
        headView=inflater?.inflate(R.layout.pull_header,viewGroup)
        return headView
    }

    override fun onPreDrag(rootView: View?) {
        headView!!.img.setImageResource(R.mipmap.huanqian_xialashuaxqian)
    }
}